import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {

    public static User login() {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你的姓名");
        String name = in.nextLine();
        System.out.println("请输入你的身份 1: 管理员  2: 普通用户-->");
        while(true) {
            char choice = in.next().charAt(0);
            in.nextLine();
            if(choice == '1') {
                System.out.println("choice = " + choice);
                return new AdminUser(name, "管理员");
            } else if(choice == '2') {
                System.out.println("choice = " + choice);
                return new NormalUser(name, "普通用户");
            }
            System.out.println("输入错误请重新输入 1: 管理员  2: 普通用户-->");
        }
    }

    public static void main(String[] args) {
        BookList bookList = new BookList();
        User user = login();
        System.out.println("hello " + user.getName() + user.getType() + "，欢迎使用图书管理系统");

        int choiceOperation = user.menu();
        while (choiceOperation != 0) {
            user.doOperation(choiceOperation, bookList);
            choiceOperation = user.menu();
        }
    }
}
